package com.imooc.activitiweb;

import com.google.common.collect.Lists;
import com.imooc.activitiweb.pojo.ProcessTaskRejectParam;
import com.imooc.activitiweb.service.ProcessTaskService;
import com.imooc.activitiweb.util.AjaxResponse;
import com.imooc.activitiweb.util.GlobalConfig;
import org.activiti.bpmn.model.*;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;

@SpringBootTest
public class Part4_Task {

    @Autowired
    private TaskService taskService;

    //任务查询
    @Test
    public void getTasks(){
        List<Task> list = taskService.createTaskQuery().list();
        for(Task tk : list){
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }
    }

    //查询我的代办任务
    @Test
    public void getTasksByAssignee(){
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee("bajie")
                .list();
        for(Task tk : list){
            System.out.println("Id："+tk.getId());
            System.out.println("Name："+tk.getName());
            System.out.println("Assignee："+tk.getAssignee());
        }

    }

    //执行任务
    @Test
    public void completeTask(){
        taskService.complete("c5528e31-514f-11eb-ab47-303a646e1823");
        System.out.println("完成任务");

    }

    @Test
    public void bohui(){
        String taskID="";
        String sql="delete from ACT_HI_TASKINST where ID_=#{taskID};";
        sql+="delete from ACT_HI_ACTINST where TASK_ID_=#{taskID};";

        sql+="delete from ACT_HI_IDENTITYLINK where TASK_ID_=#{taskID};";
        sql+="delete from ACT_RU_TASK where ID_=#{taskID};";
        sql+="delete from ACT_RU_IDENTITYLINK where TASK_ID_=#{taskID};";
    }

    //拾取任务
    @Test
    public void claimTask(){
        Task task = taskService.createTaskQuery().taskId("1f2a8edf-cefa-11ea-84aa-dcfb4875e032").singleResult();
        taskService.claim("1f2a8edf-cefa-11ea-84aa-dcfb4875e032","bajie");
    }

    //归还与交办任务
    @Test
    public void setTaskAssignee(){
        Task task = taskService.createTaskQuery().taskId("1f2a8edf-cefa-11ea-84aa-dcfb4875e032").singleResult();
        taskService.setAssignee("1f2a8edf-cefa-11ea-84aa-dcfb4875e032","null");//归还候选任务
        taskService.setAssignee("1f2a8edf-cefa-11ea-84aa-dcfb4875e032","wukong");//交办
    }


    @Autowired
    ProcessTaskService processTaskService;

    @Test
    public void ject(){
        ProcessTaskRejectParam processRejectParam=new ProcessTaskRejectParam();
        processRejectParam.setTaskId("55b64dd0-4f2f-11eb-bb59-303a646e1823");
        processRejectParam.setUserId("ghxtc");
        processRejectParam.setTargetNodeId("Activity_0mm8six");
        processRejectParam.setRejectComment("第二2次0105驳回");
        processTaskService.taskReject(processRejectParam);
    }



}
